package tdd.t1;

public class BaseFee implements Charger{

	protected int iStartMiles;
	protected int iDaytimeStartTime;
	protected double dDaytimePricePerMile;
	protected double dDaytimeStartPrice;
	protected int iNightStartTime;
	protected double dNightPricePerMile;
	protected double dNightStartPrice;
    protected TaxiFeeModel taxiFeeModel;
    
    BaseFee() {
    	this(3,6,1.6,11.0,23,2.4,13);
    }
    
    /**
	 * @param taxiFeeModel
	 */
	public BaseFee(TaxiFeeModel taxiFeeModel) {
		super();
		this.taxiFeeModel = taxiFeeModel;
	}

	BaseFee(int iStartMiles,
    		int iDaytimeStartTime,
    		double dDaytimePricePerMile,
    		double dDaytimeStartPrice,
    		int iNightStartTime,
    		double dNightPricePerMile,
    		double dNightStartPrice) {
    	this.iStartMiles = iStartMiles;	
    	this.iDaytimeStartTime = iDaytimeStartTime;
    	this.dDaytimePricePerMile = dDaytimePricePerMile;
    	this.dDaytimeStartPrice = dDaytimeStartPrice;
    	this.iNightStartTime = iNightStartTime;
    	this.dNightPricePerMile = dNightPricePerMile;
    	this.dNightStartPrice = dNightStartPrice;
    }
    
    public double chargeByTime(double miles, int time) throws Exception {    	   	
    	if(time>=this.iDaytimeStartTime&&time<this.iNightStartTime) {
    		return  Math.ceil(miles) <= this.iStartMiles? this.dDaytimeStartPrice: (Math.ceil(miles) - this.iStartMiles)*this.dDaytimePricePerMile+this.dDaytimeStartPrice;
   		} else {
    		return  Math.ceil(miles) <= this.iStartMiles? this.dNightStartPrice: (Math.ceil(miles) - this.iStartMiles)*this.dNightPricePerMile+this.dNightStartPrice;
    	}
    }
    
    public String name() {
		 return getClass().getSimpleName();
	 }
   
    private double charge1(double miles,  double unitFee, double startPrice) {
		return  Math.ceil(miles) <= this.taxiFeeModel.startMiles? startPrice: (Math.ceil(miles) - this.taxiFeeModel.startMiles)*unitFee+startPrice;   
    }
	public double chargeByMiles(double miles) {
		return this.charge1(miles, this.taxiFeeModel.pricePerMile, this.taxiFeeModel.startPrice);
	}
	
}
